<template>
  <div class="task" @scroll="loadMore">
    <div v-for="item in task" :key="item.id">
      <div class="taskComment">
        <div class="task-author">
          <img :src="`https://ss.lanqb.com/${item.profile.avatar}`" alt="" />
          <span>{{ item.profile.nickname }}</span>
        </div>
        <h3>{{ item.content }}</h3>

        <div class="task-img">
          <img :src="`https://ss.lanqb.com/${item.works.url}`" alt="" />
        </div>

        <div class="task-comment">
          <div class="commemt-author">
            <img
              :src="`https://ss.lanqb.com/${item.top_comment.avatar}`"
              alt=""
            />
            <h4>{{ item.top_comment.nickname }}</h4>
            <span
              ><img
                src="https://assets-cdn.lanqb.com/m-community/t-tag.png"
                alt=""
            /></span>
          </div>
          <p>{{ item.top_comment.content }}</p>
        </div>
      </div>
      <div
        class="line"
        style="width: 100%; height: 3px; background-color: #eee"
      ></div>
    </div>

    <div v-show="isShow" style="margin-top: 20px; text-align: center">
      加载中...
    </div>
  </div>
</template>

<script>
export default {
  name: "CommunityTask",

  data() {
    return {
      task: [],
      isShow: true,
      curPage: 1,
    };
  },
  methods: {
    loadMore(e) {
      // console.log("1111", e.target.scrollTop);
      if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight) {
        this.curPage++;
        this.isShow = true;
        fetch(`https://m.lanqb.com/api/works?type=6&page=${this.curPage}`)
          .then((res) => res.json())
          .then((data) => {
            this.task = [...this.task, ...data.data];
            this.isShow = false;
          });
      }
    },
  },
  created() {
    fetch("https://m.lanqb.com/api/works?type=6&page=1")
      .then((res) => res.json())
      .then((data) => {
        this.task = data.data;
        console.log(this.task);
      });
  },
};
</script>

<style lang="scss" scoped>
.task {
  height: calc(100vh - 48px - 44px - 60px);
  overflow-y: scroll;
  // padding: 20px;
  .taskComment {
    padding: 20px;
    // width: 100%;
    // height: 720px;
    // border-top: 5px solid #eee;
    .task-author {
      display: flex;
      align-items: center;
      img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
      }
      span {
        margin-left: 8px;
        color: #3f4345;
        font-size: 18px;
        font-weight: 400;
        font-family: PingFangSC-Regular, microsoft yahei, arial;
      }
    }
    h3 {
      color: #3f4345;
      font-size: 18px;
      margin: 10px 0;
      font-family: PingFangSC-Regular, microsoft yahei, arial;
      font-weight: 400;
    }
    .task-img {
      width: 220px;
      > img {
        width: 330px;
        height: auto;
        border-radius: 10px;
      }
    }
    .task-comment {
      margin-top: 20px;
      padding: 20px;
      background-color: #f7f7f7;
      border-radius: 10px;
      .commemt-author {
        display: flex;
        align-items: center;
        > img {
          width: 22px;
          height: 22px;
          border-radius: 50%;
        }
        h4 {
          margin-left: 5px;
        }
        span {
          display: block;
          margin-left: 8px;
          img {
            width: 60px;
            height: 19px;
          }
        }
      }
      p {
        color: #5b6164;
        margin-top: 20px;
        line-height: 24px;
      }
    }
  }
}
</style>
